package com.huluobo.a2203parkdemo.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.blankj.utilcode.util.SPUtils
import com.google.gson.Gson
import com.huluobo.a2203parkdemo.R
import com.huluobo.a2203parkdemo.databinding.ActivityRepairDetailBinding
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody


@AndroidEntryPoint
class RepairDetailActivity : BaseActivity<ActivityRepairDetailBinding, RepairViewModel>() {
    private var repairId: Int = 0
    private var repairTime: String? = ""

    override

    fun initData() {
        viewModel.repairCompleteSuccess.observe(this) {
            binding.repairDetailValuesTv.text = it
        }
    }

    override fun initView() {
        repairId = intent.getIntExtra(Const.PARAM_REPAIR_ID, 0)
        repairTime = intent.getStringExtra("time").toString()
//        {
//            "repairId": 0,
//            "sign": "string",
//            "time": "string",
//            "userId": 0,
//            "verify": 0
//        }
        binding.repairDetailBtn.setOnClickListener {
            val map = mutableMapOf<String, Any>()
            map[Const.PARAM_REPAIR_ID] = repairId
            map[Const.PARAM_TIME] = repairTime!!
            map[Const.PARAM_USER_ID] = SPUtils.getInstance().getInt(Const.PARAM_USER_ID)
            map["verify"] = 1

            val json = Gson().toJson(map)
            val body = RequestBody.create(Const.MEDIA_TYPE.toMediaTypeOrNull(), json)

            viewModel.repairComplete(body)
        }
    }
}